package com.example.demo;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/msg")
public class ProduceController {

	
	private JmsTemplate template;
	@Autowired
	public  ProduceController(JmsTemplate template) {
		this.template=template;
	}
	@GetMapping("send")
	public Mono<String> send(final String content){
		template.send("test.queue",new MessageCreator() {
			
			@Override
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(content);
			}
		});
		
		return Mono.just("===消息发送："+content);
	}
	
	public void setTemplate(JmsTemplate template) {
		this.template = template;
	}
	
	
}
